<%@page isELIgnored="false" pageEncoding="UTF-8" contentType="text/html; UTF-8" %>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>持明法洲登录页面</title>
		<link rel="stylesheet" href="layui/css/layui.css">
		 <link rel="stylesheet" href="css/main.css" media="all">
		 <link rel="stylesheet" href="css/plugins/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
	</head>
	
	<body class="layui-layout-login">
	<div class="login-bg">
	    <div class="cover"></div>
	</div>
	<div class="login-content" >
	    <h1 class="login-box-title"><i class="fa fa-fw fa-user"></i>登录</h1>
	    <form class="layui-form" <%--action="${pageContext.request.contextPath}/admin/loginAdmin"--%> method="post">
			
	        <div class="layui-form-item">
	            <label class="layui-icon layui-icon-username" for="username"></label>
	            <input class="layui-input" type="text" name="username" id="username" placeholder="用户名">
	        </div>
			
	        <div class="layui-form-item">
	            <label class="layui-icon layui-icon-password" for="password"></label>
	            <input class="layui-input" type="password" name="password" id="password" placeholder="密码">
	        </div>
			
	        <div class="layui-form-item captcha-item">
	            <label class="layui-icon layui-icon-vercode"></label>
	            <input class="layui-input" type="text" name="code" autocomplete="off" placeholder="验证码">
				<img id="addPic" class="captcha-img" src="${pageContext.request.contextPath}/validateCode" />
	        </div>
			
	        <button type="submit" lay-submit lay-filter="loginButton" class="layui-btn layui-btn-fluid ajax-login"><i class="fa fa-sign-in fa-lg fa-fw"></i> 登录</button>
	    </form>
	</div>
	</body>
	<script src="layui/layui.js" type="text/javascript"></script>
	<script src="js/jquery-1.12.4.js" type="text/javascript"></script>
	<script>
		layui.use(['form','jquery','layer'],function () {
			var form = layui.form;
			var $ = layui.jquery;
			var layer = layui.layer;
			form.on('submit(loginButton)', function(data){
				console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
				console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
				console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
				function msg(message){
					layer.msg(message, {
						icon: 1,
						time: 2000 //2秒关闭（如果不配置，默认是3秒）
					}, function(){
						//do something
					});
				}
				$.ajax({
					url:'${pageContext.request.contextPath}/admin/login',
					data:data.field,
					type:"POST",
					success:function (data) {
						if(data.status==0){
							msg(data.data);
						}else if(data.status==1){
							msg(data.data);
							window.location.href='main.jsp'
						}else if(data.status==2){
							msg(data.data);
						}else if(data.status==3){
							window.location.reload();
							msg(data.data);
						}
					}
				})


				return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
			});
		})
	</script>
</html>
